From: Derk-Jan Hartman Date: Fri, 19 May 2017 11:36:04 +0000 (+0200) Subject: MimeAnalyzer: Add testcases for mp3 detection X-Git-Tag: 1.31.0-rc.0~2438^2 X-Git-Url: http://git.cyclocoop.org/%22.%24info%5B?a=commitdiff_plain;h=c6235442b4a8e00ba09396cf278862ae9ae5c225;p=lhc%2Fweb%2Fwiklou.git MimeAnalyzer: Add testcases for mp3 detection This is a follow-up to change Ie1a63aa Bug: T115170 Change-Id: Iab5e19e1dd26b0d88c72ad7253cd11e865c5e008 --- diff --git a/.gitattributes b/.gitattributes index 09f86a3280..f230c60f7e 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,3 +1,4 @@ *.sh eol=lf *.icc binary *.webp binary +*.mp3 binary \ No newline at end of file diff --git a/tests/phpunit/data/media/say-test-mpeg1.mp3 b/tests/phpunit/data/media/say-test-mpeg1.mp3 new file mode 100644 index 0000000000..b3a63183e7 Binary files /dev/null and b/tests/phpunit/data/media/say-test-mpeg1.mp3 differ diff --git a/tests/phpunit/data/media/say-test-mpeg2.5.mp3 b/tests/phpunit/data/media/say-test-mpeg2.5.mp3 new file mode 100644 index 0000000000..e6743a8080 Binary files /dev/null and b/tests/phpunit/data/media/say-test-mpeg2.5.mp3 differ diff --git a/tests/phpunit/data/media/say-test-mpeg2.mp3 b/tests/phpunit/data/media/say-test-mpeg2.mp3 new file mode 100644 index 0000000000..8b2aaa2cd6 Binary files /dev/null and b/tests/phpunit/data/media/say-test-mpeg2.mp3 differ diff --git a/tests/phpunit/data/media/say-test-with-id3.mp3 b/tests/phpunit/data/media/say-test-with-id3.mp3 new file mode 100644 index 0000000000..04205d502a Binary files /dev/null and b/tests/phpunit/data/media/say-test-with-id3.mp3 differ diff --git a/tests/phpunit/includes/libs/mime/MimeAnalyzerTest.php b/tests/phpunit/includes/libs/mime/MimeAnalyzerTest.php index 787d9a8837..bf2a3f665c 100644 --- a/tests/phpunit/includes/libs/mime/MimeAnalyzerTest.php +++ b/tests/phpunit/includes/libs/mime/MimeAnalyzerTest.php @@ -1,4 +1,8 @@ mimeAnalyzer ) ); + $method = $class->getMethod( 'doGuessMimeType' ); + $method->setAccessible( true ); + return $method->invokeArgs( $this->mimeAnalyzer, $parameters ); + } + /** * @dataProvider providerImproveTypeFromExtension * @param string $ext File extension (no leading dot) @@ -69,4 +80,49 @@ class MimeMagicTest extends PHPUnit_Framework_TestCase { $actualType = $this->mimeAnalyzer->getMediaType( $oggFile, 'application/ogg' ); $this->assertEquals( $actualType, MEDIATYPE_AUDIO ); } + + /** + * Test to make sure that mp3 files are detected as audio type + */ + function testMP3AsAudio() { + $file = __DIR__ . '/../../../data/media/say-test-with-id3.mp3'; + $actualType = $this->mimeAnalyzer->getMediaType( $file ); + $this->assertEquals( MEDIATYPE_AUDIO, $actualType ); + } + + /** + * Test to make sure that MP3 with id3 tag is recognized + */ + function testMP3WithID3Recognize() { + $file = __DIR__ . '/../../../data/media/say-test-with-id3.mp3'; + $actualType = $this->doGuessMimeType( [ $file, 'mp3' ] ); + $this->assertEquals( 'audio/mpeg', $actualType ); + } + + /** + * Test to make sure that MP3 without id3 tag is recognized (MPEG-1 sample rates) + */ + function testMP3NoID3RecognizeMPEG1() { + $file = __DIR__ . '/../../../data/media/say-test-mpeg1.mp3'; + $actualType = $this->doGuessMimeType( [ $file, 'mp3' ] ); + $this->assertEquals( 'audio/mpeg', $actualType ); + } + + /** + * Test to make sure that MP3 without id3 tag is recognized (MPEG-2 sample rates) + */ + function testMP3NoID3RecognizeMPEG2() { + $file = __DIR__ . '/../../../data/media/say-test-mpeg2.mp3'; + $actualType = $this->doGuessMimeType( [ $file, 'mp3' ] ); + $this->assertEquals( 'audio/mpeg', $actualType ); + } + + /** + * Test to make sure that MP3 without id3 tag is recognized (MPEG-2.5 sample rates) + */ + function testMP3NoID3RecognizeMPEG2_5() { + $file = __DIR__ . '/../../../data/media/say-test-mpeg2.5.mp3'; + $actualType = $this->doGuessMimeType( [ $file, 'mp3' ] ); + $this->assertEquals( 'audio/mpeg', $actualType ); + } }